package bio.demo2;

import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
import java.net.Socket;
import java.util.Scanner;

/**
 * @author charwayH
 * 目标: 服务端可以反复的接收消息，客户端可以反复的发送消息
 */
public class Client {
    public static void main(String[] args) {
        try {
            // 1.创建一个Socket对象请求服务端连接
            Socket socket = new Socket("127.0.0.1", 9998);
            // 2.让Socket对象中获取字节输出流
            OutputStream os = socket.getOutputStream();
            // 3.把字节输出流包装成打印流
            PrintStream ps = new PrintStream(os);
            Scanner scanner = new Scanner(System.in);
            while (true) {
                System.out.println("请输入消息内容");
                String msg = scanner.nextLine();
                ps.println(msg);
                ps.flush();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}